package com.iasku.util;


import java.util.Map;
import java.util.Map.Entry;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

public class SoapUtil {
	private static SoapObject callWebService(SoapObject req,String url,String soapAction){
		HttpTransportSE ht = new HttpTransportSE(url);
		ht.debug = true;
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.bodyOut = req;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(req);
		try {
			ht.call(soapAction, envelope);
			ht.getConnection().disconnect();
		} catch (Exception e) {
			e.printStackTrace();
		} 
		System.out.println("body=>"+envelope.bodyIn);
		SoapObject result = (SoapObject) envelope.bodyIn;
		return result;
	}
	
	public static SoapObject getResponseSoapObject(Map<String,String> params,
	                String methodname,String namespace,String url){
	    SoapObject req = new SoapObject(namespace, methodname);
	    for(Entry<String,String> entry : params.entrySet()){
	        req.addProperty(entry.getKey(),entry.getValue());
	    }
	    return callWebService(req, url, namespace + methodname);
	}
}
